package com.jch.udpdemo.server;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;

public class Server {

    public static void main(String[] args) {
        EventLoopGroup group = new NioEventLoopGroup();

        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(group)
                .channel(NioDatagramChannel.class)
                .option(ChannelOption.SO_BROADCAST,true) // 广播
                .option(ChannelOption.SO_RCVBUF,2048 * 1024) // 设置读缓冲区为2M
                .option(ChannelOption.SO_SNDBUF,1024 * 1024) // 设置写缓冲区为1M
                .handler(new ServerChannelInitializer());

        try {
            ChannelFuture f = bootstrap.bind(1122).sync();
            System.out.println("UDP Server Start");
            f.channel().closeFuture().sync();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            group.shutdownGracefully();
        }
    }
}
